export function getCookie(name: string) {
  if (document.cookie.length > 0) {
    let start = document.cookie.indexOf(`${name}=`)
    if (start !== -1) {
      start = start + name.length + 1
      let end = document.cookie.indexOf(";", start)
      if (end === -1) end = document.cookie.length
      return unescape(document.cookie.substring(start, end))
    }
  }
  return ""
}

export function setCookie(name: string, value: string, expiredays: number) {
  const exdate = new Date()
  exdate.setDate(exdate.getDate() + expiredays)
  document.cookie = `${name}=${escape(value)}${
    expiredays === null ? "" : `;expires=${exdate.toUTCString()}`
  };path=/`
}

export function delCookie(name: string, value: string) {
  const exdate = new Date()
  exdate.setDate(exdate.getDate() - 1)
  document.cookie = `${name}=${escape(value)};expires=${exdate.toUTCString()}};path=/`
}
